/**
 *合作机构集合。 
 **/
Ext.define("ES.store.CooperationStore",{
    extend:"Ext.data.Store",
    model:"ES.model.CooperationModel",
    pageSize:20,
    remoteSort:true,
    autoLoad: false,
    proxy:{
            type:"ajax",
            url:"Cooperation!list.action",
            reader:{
                type:"json",
                root:"dataSource.entityList",
                totalProperty:"dataSource.totalCounts"
            },
            listeners:{
                exception:function(proxy, resp, operation, opt){
                    Ext.MessageBox.show({
                        title:"远程异常",
                        msg:operation.getError(),
                        icon:Ext.MessageBox.ERROR,
                        buttons:Ext.Msg.OK
                    });
                }
            }
    },
    listeners:{
        beforeload:function(store, operation){
            Ext.getBody().mask("正在加载数据，请稍后...");
            Ext.apply(store.proxy.extraParams,{
                ascProperty:"CooperationTime",
                asc:false
            });
        },
        load:function(){
            Ext.getBody().unmask();
        },
        update:function(store, record){
            var currPage = store.currentPage;
            Ext.Ajax.request({
                url:"CooperationEdit!update.action",
                params:{
                    cooperationID:record.get("cooperationID"),
                    cooperationCode:record.get("cooperationCode"),
                    cooperationName:record.get("cooperationName"),
                    cooperationWay:record.get("cooperationWay"),
                    authorizationCode:record.get("authorizationCode"),
                    hostURL:record.get("hostURL"),
                    siteURL:record.get("siteURL"),
                    cooperationTime:record.get("cooperationTime"),
                    profitPercent:record.get("profitPercent"),
                    telPhone:record.get("telPhone"),
                    emailAddress:record.get("emailAddress"),
                    linkName:record.get("linkName"),
                    IDCard:record.get("IDCard"),
                    bankName:record.get("bankName"),
                    bankNumber:record.get("bankNumber"),
                    bankAddress:record.get("bankAddress"),
                    status:record.get("status")
                },
                method:"POST",
                success:function(){
                    store.removeAll();
                    store.loadPage(currPage);
                }
            });
        },
        remove:function(store, record){
             var currPage = store.currentPage;
              Ext.Ajax.request({
                   url:"CooperationEdit!delete.action",
                   params:{
                       cooperationID:record.get("cooperationID")
                   },
                   method:"POST",
                   success:function(){
                    store.removeAll();
                    store.loadPage(currPage);
                 }
              });
        }
    }
});